$(function () {
  const layer = layui.layer
  const nexts = document.querySelectorAll('.next')
  const boxs = document.querySelectorAll('.box')
  const yellow = document.querySelectorAll('.title span')
  nexts[0].addEventListener('click', async function () {
    const phone = document.querySelector('#phone').value.trim()
    if (phone.length <= 0) {
      return alert('输入内容不可为空')
    }
    $(this).parent().hide()

    boxs[1].style.display = 'block'
    document.querySelector('.title .active').classList.remove('active')
    yellow[1].classList.add('active')


    const dataObj = { phone }
    const { data } = await axios.get('http://124.223.14.236:3001/api/user/findPwd', {
      params: dataObj
    })
    console.log(data.data);
    document.querySelector('#id').value = data.data.id
    document.querySelector('.phone').value = data.data.phone
    document.querySelector('#question').value = data.data.question

    if (!data.success) {
      return layer.msg(data.msg)
    }
    // if (answer!==da.answer) {
    // return layer.msg('密保答案不正确')
    // }

    nexts[1].addEventListener('click', function () {
      $(this).parent().hide()
      boxs[2].style.display = 'block'
      document.querySelector('.title .active').classList.remove('active')
      yellow[2].classList.add('active')
    })

    nexts[2].addEventListener('click', async function () {
      const id = document.querySelector('#id').value
      const answer = document.querySelector('#answer').value.trim()
      const password = document.querySelector('#password').value.trim()
      const { data } = await axios.post('http://124.223.14.236:3001/api/user/resetPwd', {
        id,
        password,
        answer,
      })
      console.log(data);
      if (!data.success) {
        return layer.msg(data.msg)
      }
      layer.msg('重置密码成功!')
      location.href = '/01-loginBaseCode/login.html'


    })




  })

  const prve = document.querySelectorAll('.prve')
  prve[0].addEventListener('click', function () {
    $(this).parent().hide()
    const boxs = document.querySelectorAll('.box')
    boxs[0].style.display = 'block'
    document.querySelector('.title .active').classList.remove('active')
    yellow[0].classList.add('active')
  })
  prve[1].addEventListener('click', function () {
    $(this).parent().hide()
    const boxs = document.querySelectorAll('.box')
    boxs[1].style.display = 'block'
    document.querySelector('.title .active').classList.remove('active')
    yellow[1].classList.add('active')
  })

})